<?php
/**
 * 引入composer并使用
 **/
require_once __DIR__ . '/../../vendor/autoload.php';

use think\Validate;

class EmployeeValidate extends Validate
{
    protected $rule = [
        'operator_id' => 'require',
        'school_id' => 'require',
        'name' => 'require|max:50',
        'employee_number' => 'require|max:20',
        'position' => 'max:50',
        'avatar' => 'max:255',
        'introduction' => 'max:500',
        'status' => 'integer|in:0,1'
    ];

    protected $message = [
        'operator_id.require' => '运营ID不能为空',
        'school_id.require' => '学校ID不能为空',
        'name.require' => '姓名不能为空',
        'name.max' => '姓名最多50个字符',
        'employee_number.require' => '从业人员编号不能为空',
        'employee_number.max' => '从业人员编号最多20个字符',
        'position.max' => '职位最多50个字符',
        'avatar.max' => '头像链接最多255个字符',
        'introduction.max' => '简介最多500个字符',
        'status.integer' => '状态必须是整数',
        'status.in' => '状态只能是0或1'
    ];

    // 定义验证场景
    protected $scene = [
        'add' => [ // 添加场景验证所有必填项
            'operator_id', 'school_id', 'name', 'employee_number', 'status'
        ],
        'edit' => [ // 修改场景（排除employee_number唯一性验证，假设编号不可修改）
            'operator_id', 'school_id', 'name', 'position', 'avatar', 'introduction', 'status'
        ],
        'delete' => [ // 删除场景验证记录存在性（需配合模型验证）
            'id' => 'require|integer'
        ]
    ];
}